from sqlalchemy import Column, Integer, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
from datetime import datetime

Base = declarative_base()


class TaskSite(Base):
    __tablename__ = 'task_site'

    id = Column(Integer, primary_key=True, index=True)
    type_name = Column(String(100), nullable=False)
    site_name = Column(String(100), nullable=False)
    origin = Column(String(100), nullable=False)
    site_url = Column(String(100), nullable=False)
    list_link = Column(String(100), nullable=False)
    method = Column(String(10), nullable=False)
    param = Column(String(255), nullable=False)
    type = Column(String(10), nullable=False)
    cookie = Column(String(1000), nullable=False)
    user_agent = Column(String(1000), nullable=False)
    status = Column(Integer, nullable=False, default=1)
    last_execute_time = Column(DateTime, default=datetime.now)
    sort = Column(Integer, nullable=False, default=1)


class TaskVideo(Base):
    __tablename__ = 'task_videos'

    id = Column(String(64), primary_key=True, index=True)
    v_id = Column(String(64), nullable=False)
    type_name = Column(String(100), nullable=False)
    site_name = Column(String(100), nullable=False)
    title = Column(String(255), nullable=False)
    title_en = Column(String(255), nullable=False)
    image_url = Column(String(255), nullable=False)
    video_url = Column(String(255), nullable=False)
    video_path = Column(String(255), nullable=False)
    site_url = Column(String(255), nullable=False)
    author = Column(String(50), nullable=False)
    play_num = Column(Integer, default=0)
    duration = Column(Integer, default=0)
    duration_str = Column(String(100))
    create_time = Column(DateTime, default=datetime.now)
    size = Column(String(50), nullable=False)
    release_time = Column(DateTime, nullable=False)
    is_down = Column(Integer, default=0)


class TaskErrorRequest(Base):
    __tablename__ = 'task_error_request'

    id = Column(Integer, primary_key=True, index=True)
    url = Column(String(255), nullable=False)
    error_message = Column(String(255), nullable=False)
    add_time = Column(DateTime, default=datetime.now)


class VideoSource(Base):
    __tablename__ = 'video_source'

    id = Column(String(64), primary_key=True, index=True)
    user_id = Column(String(64), nullable=False)
    actors = Column(String(500), nullable=False)
    category = Column(String(500), nullable=False)
    tags = Column(String(1000), nullable=False)
    cover = Column(String(255), nullable=False)
    title = Column(String(255), nullable=False)
    preview = Column(String(255), nullable=False)
    play_path = Column(String(255), nullable=False)
    start_time = Column(DateTime, nullable=False)
    end_time = Column(DateTime, nullable=False)
    recom_start = Column(Integer, default=0)
    planum = Column(Integer, default=0)
    favnum = Column(Integer, default=0)
    likenum = Column(Integer, default=0)
    diskenum = Column(Integer, default=0)
    sharenum = Column(Integer, default=0)
    downnum = Column(Integer, default=0)
    duration = Column(String(100), default=0)
    play_time = Column(Integer, default=0)
    langs = Column(Integer, default=0)
    type = Column(Integer, default=0)
    online_time = Column(String(13), nullable=False)
    offline_time = Column(String(13), nullable=False)
    price = Column(Integer, default=0)
    sort = Column(Integer, default=0)
    remark = Column(String(255), nullable=False)
    create_time = Column(String(13), nullable=False)
    show_type = Column(Integer, default=1)
    state = Column(Integer, default=1)

# class VideoType(Base):
#     __tablename__ = 'video_type'
#
#     id = Column(String(64), primary_key=True, index=True)
#     name = Column(String(64), nullable=False)
#     state = Column(Integer, default=1)

class VideoCategory(Base):
    __tablename__ = 'video_category'

    id = Column(String(64), primary_key=True, index=True)
    name = Column(String(64), nullable=False)